package com.atguigu.mq.topic;

import com.atguigu.mq.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Producer {
    public static void main(String[] args) throws Exception {
        String exchange="topic_change";
        String queue="topic_queue1";
        String queue2="topic_queue2";
        String queue3="topic_queue3";
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        //BuiltinExchangeType.FANOUT 广播式交换机
        //BuiltinExchangeType.DIRECT 定向路由
        channel.exchangeDeclare(exchange, BuiltinExchangeType.TOPIC,true,false,null);

        //声明队列
        channel.queueDeclare(queue,true,false,false,null);
        channel.queueDeclare(queue2,true,false,false,null);
        channel.queueDeclare(queue3,true,false,false,null);
        //绑定关系
        channel.queueBind(queue,exchange,"hello.*");
        channel.queueBind(queue2,exchange,"hello.#");
        channel.queueBind(queue3,exchange,"hello.*.*");

        String message="hellomq_topic";
        channel.basicPublish(exchange,"hello.a.b",null,message.getBytes());

        channel.close();
        connection.close();
    }
}
